import {LogLanguage} from "../dist/index.js"

// 测试所有TID格式识别
const testCases = [
  // 1. 标准格式：TID:xxx
  "2024-01-15 10:30:45 [INFO] TID:abc123.def456.ghi789 [service.SBYBaseService:70] Processing request",
  
  // 2. 标准格式：[TID:xxx]
  "2024-01-15 10:30:45 [ERROR] [TID:abc123.def456.ghi789] [service.SBYBaseService:70] Error occurred",
  
  // 3. 新格式：[TID:] [xxx]
  "2024-01-15 10:30:45 [WARNING] [TID:] [fcdfba1a21214a8e97c7d8fd1a8aa287.1161.17544505317727189] [service.SBYBaseService:70] Warning message",
  
  // 4. 新格式小写：[tid:] [xxx]
  "2024-01-15 10:30:45 [FATAL] [tid:] [fcdfba1a21214a8e97c7d8fd1a8aa287.1161.17544505317727189] Critical error",
  
  // 5. 混合格式：标准 + 新格式
  "2024-01-15 10:30:45 [INFO] TID:abc123 [TID:] [fcdfba1a21214a8e97c7d8fd1a8aa287.1161.17544505317727189] [service.SBYBaseService:70] Processing request",
  
  // 6. 只有新格式
  "2024-01-15 10:30:45 [DEBUG] [TID:] [fcdfba1a21214a8e97c7d8fd1a8aa287.1161.17544505317727189] Debug message",
  
  // 7. 复杂格式
  "2024-01-15 10:30:45 [INFO] [TID:] [fcdfba1a21214a8e97c7d8fd1a8aa287.1161.17544505317727189] (com.cn.yft.ora.bank.sby.service.SBYBaseService:70) Processing request with id=\"12345\" and count=100"
]

console.log("=== 所有 TID 格式识别测试 ===")

testCases.forEach((testCase, index) => {
  console.log(`\n测试 ${index + 1}:`)
  console.log(`输入: ${testCase}`)
  
  const tree = LogLanguage.parser.parse(testCase)
  let foundNodes = []
  
  tree.iterate({
    enter: (node) => {
      foundNodes.push({
        name: node.type.name,
        from: node.from,
        to: node.to,
        text: testCase.slice(node.from, node.to)
      })
    }
  })
  
  // 检查TID相关节点
  const tidExpressionNodes = foundNodes.filter(node => node.name === 'TIDExpression')
  const tidWithEmptyPrefixNodes = foundNodes.filter(node => node.name === 'TIDWithEmptyPrefixExpression')
  
  console.log("TID 识别结果:")
  
  if (tidExpressionNodes.length > 0) {
    console.log("✓ 标准 TID 格式识别成功")
    tidExpressionNodes.forEach(node => {
      console.log(`  - TIDExpression: "${node.text}"`)
    })
  }
  
  if (tidWithEmptyPrefixNodes.length > 0) {
    console.log("✓ 新 TID 格式识别成功")
    tidWithEmptyPrefixNodes.forEach(node => {
      console.log(`  - TIDWithEmptyPrefixExpression: "${node.text}"`)
    })
  }
  
  if (tidExpressionNodes.length === 0 && tidWithEmptyPrefixNodes.length === 0) {
    console.log("✗ 未找到任何 TID 格式")
  }
  
  // 检查其他功能
  const dateNodes = foundNodes.filter(node => node.name === 'DATEExpression')
  const logLevelNodes = foundNodes.filter(node => 
    node.name.includes('Expression') && 
    (node.name.includes('FATAL') || node.name.includes('ERROR') || 
     node.name.includes('INFO') || node.name.includes('WARNING') || 
     node.name.includes('Debug'))
  )
  const classPathNodes = foundNodes.filter(node => node.name === 'CLASSPATHExpression')
  const stringNodes = foundNodes.filter(node => node.name === 'StringLiteral')
  const numberNodes = foundNodes.filter(node => node.name === 'NumberExpression')
  
  console.log("\n其他功能检查:")
  console.log(`  - 日期识别: ${dateNodes.length > 0 ? '✓' : '✗'}`)
  console.log(`  - 日志级别识别: ${logLevelNodes.length > 0 ? '✓' : '✗'}`)
  console.log(`  - 类路径识别: ${classPathNodes.length > 0 ? '✓' : '✗'}`)
  console.log(`  - 字符串识别: ${stringNodes.length > 0 ? '✓' : '✗'}`)
  console.log(`  - 数字识别: ${numberNodes.length > 0 ? '✓' : '✗'}`)
})
